// -----------------------------
// Author: 		Dhaenens Gert 
// Creation: 	2/19/2015 10:39:31 PM				
// -----------------------------

#ifndef _JobManager_h
#define _JobManager_h

#include "Common.h"

namespace Flow
{

	class Job;
	class IThread;
	class IMutex;

	class JobManager
	{
	public:

		JobManager();
		~JobManager();

		Bool	Initialize();
		void	ProcessJobs(ProcessOption::Enum option);

		void	QueueJob(Job* lpJob);

		void	ClearJobs();
		void	ClearThreads(Bool bWaitForThreads = false);
		void	ClearAll(Bool bWaitForThreads = false);

		void	WaitForJobs() const;
		Bool	HasJobsAvailable() const;

	private:

		IThread*		GetAvailableThread();
		void			ProcessSingleJob();

		static void		ThreadProc(void* lpArgs);

		UInt32			m_MaxThreads;
		IThread**		m_Threads;

		IMutex*			m_QueueLock;
		queue<Job*>		m_Jobs;

		JobManager(const JobManager& refJobManager);
		JobManager& operator=(const JobManager& refJobManager);
	};

}

#endif